telephone = []
print("欢迎使用通讯录")
print("1.添加联系人")
print("2.查看通讯录")
print("3.删除联系人")
print("4.修改联系人")
print("5.查找联系人")
print("6.退出")
while True:
    tele_dict = {}
    number = input("请输入功能序号")
    if "1" == number:
        tele_name = input("请输入联系人姓名")
        tele_phone = input("请输入联系人电话")
        tele_email = input("请输入联系人邮箱")
        if tele_name.strip() == '':
            print("请输入正确信息")
            continue
        else:
            tele_dict.update({'姓名': tele_name, '电话': tele_phone, '邮箱': tele_email})
            telephone.append(tele_dict)
            print("保存成功")
    elif "2" == number:
        if len(telephone) == 0:
            print("通讯录无联系人")
        else:
            for i in telephone:
                for title, info in i.items():
                    print(title + ':' + info)
    elif "3" == number:
        if len(telephone) != 0:
            del_name = input("请输入要删除的联系人的名字")
            for i in telephone:
                if del_name in i.values():
                    telephone.remove(i)
                    print(telephone)
                    print("删除成功")
                else:
                    print("联系人不在通讯录中")
        else:
            print("通讯录无联系人")
    elif "4" == number:
        if len(telephone) != 0:
            mod_name = input("请输入要修改的联系人姓名")
            for i in telephone:
                if mod_name in i.values():
                    index_num = telephone.index(i)
                    dict_person = telephone[index_num]
                    for title, info in dict_person.items():
                        print(title + ":" + info)
                    new_name = input("请输入姓名")
                    new_phone = input("请输入电话")
                    new_email = input("请输入邮箱")
                    dict_person.update(姓名=new_name)
                    dict_person.update(电话=new_phone)
                    dict_person.update(邮箱=new_email)
                    print(telephone)
        else:
            print("通讯录无信息")
    elif "5" == number:
        if len(telephone) != 0:
            qurry_name = input("请输入要查询的联系人姓名")
            for i in telephone:
                if qurry_name in i.values():
                    index_num = telephone.index(i)
                    for title, info in telephone[index_num].items():
                        print(title + ":" + info)
                    break
                else:
                    print("联系人不在通讯录")
        else:
            print("通讯录无信息")
    elif "6" == number:
        break
